const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const name = wx.getStorageSync("name");
    this.setData({
      name
    });
  },
  changeName: function(e) {
    this.setData({
      name: e.detail.value
    });
  },
  setName: function() {
    const name = this.data.name;
    if(name.length===0){
      wx.showToast({
        title: "请输入全名",
        icon: 'none'
      });
      return;
    }
    const url = app.globalData.url;
    const openId = app.globalData.openId;
    wx.request({
      url: url + '/coach/updateName',
      data: {
        openId,
        name
      },
      method:'POST',
      success: function(response) {
        if (response.data.success) {
          wx.navigateBack({
            delta: 1
          });
        } else {
          wx.showToast({
            title: response.data.message,
            icon: 'none'
          })
        }
      }
    })
  }
})